using System;
using System.Collections;
using Scenario.WorkflowEngine.DataModel;

namespace Scenario.WorkflowEngine.DataModel.WorkflowProcesses
{
	//*********************************************************************
	//
	// XmlVariables Class
	//
	// The XmlVariables class represents a collection base of XmlVariable
	// Its imports methods from WAPI.XmlObjectSet like get set and add
	// XmlVariables Has no fields
	//
	//*********************************************************************

	public class XMLLogs : bOS.XML.Data.XMLObjectSet
	{
		public const string MAIN_NODE		= "Logs";

		/** FIELDS **/

		/** no fields **/

		/** CONSTRUCTORS **/

		/** CONSTRUCTOR Empty **/
		public XMLLogs()
		{
			this.Init();
		}

		/** CONSTRUCTOR Width xml parsering**/
		public XMLLogs(System.Xml.XmlNode nodeList)
		{
			this.Parse (nodeList);
		}

		/** INSTANCE METHODS **/

		public override void Init()
		{
			this.RemoveAll();
		}

		override public void Parse(System.Xml.XmlNode nodeList)
		{
			this.Init();

			System.Xml.XmlNode node;

			for ( int i=0; i<nodeList.ChildNodes.Count;i++)
			{
				node = nodeList.ChildNodes[i];

				switch ( node.Name) 
				{
					case XMLLog.MAIN_NODE:
						this.Add ( new XMLLog(node));
						break;
				}
			}
		}

		override public bOS.XML.XMLNode GetXMLNode()
		{
			bOS.XML.XMLNode xmlNode = new bOS.XML.XMLNode(XMLLogs.MAIN_NODE);

			XMLLog log = null;
			System.Collections.IEnumerator myEnumerator = this.GetEnumerator();
			while ( myEnumerator.MoveNext() )
			{
				log = (XMLLog)myEnumerator.Current;

				xmlNode.AddNode ( log.GetXMLNode() );
			}

			return xmlNode;
		}
		/** SORTING  FIELDS **/

		public void AddStatus(string sOwner, string sDate, string sStatus)
		{
			XMLLog myLog = null;
			System.Collections.IEnumerator myEnumerator = this.GetEnumerator();
			while ( myEnumerator.MoveNext() )
			{
				myLog = (XMLLog)myEnumerator.Current;

				if ( myLog.Owner == sOwner )
				{
					myLog.AddStatus(sDate, sStatus);

					return;
				}
			}

			XMLLog log = new XMLLog();
			log.Owner = sOwner;
			log.Status = sStatus;
			log.Date = sDate;

			this.Add ( log );
		}
	}
}
